package com.yuntsg.nnsfcp.controller.back;


import com.yuntsg.nnsfcp.common.beans.ResultBean;
import com.yuntsg.nnsfcp.common.utils.CheckUtil;
import com.yuntsg.nnsfcp.front.entity.TRole;
import com.yuntsg.nnsfcp.service.back.Role.RoleService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/sys")
@RestController
@Slf4j
//@Api(tags = "组织模块-角色管理")
public class RoleController {


    @Autowired
    private RoleService roleService;

    @PostMapping("/add-role")
    //@ApiOperation(value = "新增角色接口")
    public ResultBean<Object> addRole(@RequestBody TRole vo) {
        return new ResultBean<>(roleService.addRole(vo));
    }

    @GetMapping("/del-role/{id}")
    //@ApiOperation(value = "删除角色接口")
//    @ApiImplicitParam(value = "id", name = "id", required = true, dataType = "String")
    public ResultBean<Object> deletedRole(@PathVariable("id") Integer id) {
        roleService.deletedRole(id);
        return new ResultBean<>("222");
    }

    @PostMapping("/role")
    //@ApiOperation(value = "更新角色信息接口")
    public ResultBean<Object> updateRole(@RequestBody TRole vo) {
        if (StringUtils.isEmpty(vo.getId())) {
            CheckUtil.check(false, "id不能为空");
        }
        roleService.updateRole(vo);
        return new ResultBean<>();
    }

    @GetMapping("/role/{id}")
    //@ApiOperation(value = "查询角色详情接口")
//    @ApiImplicitParam(value = "id", name = "id", required = true, dataType = "String")
    public ResultBean<Object> detailRoleInfo(@PathVariable("id") Integer id) {
        return new ResultBean<>(roleService.detailInfo(id));
    }

    @PostMapping("/roles")
    //@ApiOperation(value = "分页获取角色信息接口")
    public ResultBean<Object> pageInfo(@RequestBody TRole vo) {
        return new ResultBean<>(roleService.pageInfo(vo));
    }


    @GetMapping("/allRole")
    //@ApiOperation(value = "获取角色信息")
    public ResultBean<Object> selectAllRole() {
        return new ResultBean<>(roleService.selectAllRoles());
    }

}
